package com.ss.ttvideoengine.log;

import com.ss.ttm.player.IMediaPlayerClient;
import com.ss.ttvideoengine.TTVideoEngine;
import com.ss.ttvideoengine.d.TTVideoError;

import org.json.JSONObject;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public final class c {
    public static final class a {
        public final WeakReference<TTVideoEngine> mTTVideoEngineRef;

        public a(TTVideoEngine arg2) {
            this.mTTVideoEngineRef = new WeakReference(arg2);
        }
    }

    public a a;
    public String b;
    public com.ss.ttvideoengine.log.a c;
    public boolean d;
    public ArrayList e;
    public ArrayList<TTVideoError> mTTVideoErrorList;
    public ArrayList g;
    public ArrayList h;
    public String preResolutionString;
    public String currentResolutionString;
    public Map k;
    public String l;
    private Map m;

    public c(a arg2) {
        this.b = "";
        this.preResolutionString = "";
        this.currentResolutionString = "";
        this.l = "";
        this.a = arg2;
        this.c = new com.ss.ttvideoengine.log.a();
        this.e = new ArrayList();
        this.mTTVideoErrorList = new ArrayList();
        this.g = new ArrayList();
        this.h = new ArrayList();
        this.k = new HashMap();
        this.d = true;
    }

    public final void a(String arg5) {
        this.c();
        this.m = null;
        this.c = new com.ss.ttvideoengine.log.a();
        this.c.v = arg5;
        this.c.pt = System.currentTimeMillis();
    }

    public final void a(String arg1, String arg2) {
        this.preResolutionString = arg2;
        this.currentResolutionString = arg1;
    }

    public final void a() {
        this.d = false;
        this.c.vt = System.currentTimeMillis();
    }

    public final void a(Map map, TTVideoError arg6) {
        if (arg6 != null) {
            this.k.put("api", arg6.toMap());
        } else if (map != null) {
            this.m = map;
            this.c.at = System.currentTimeMillis();
        }
    }

    public final void b() {
        if (this.d) {
            this.c.lt = System.currentTimeMillis();
        } else {
            this.c.errorTime = System.currentTimeMillis();
        }

        this.e();
        this.c();
        this.c = new com.ss.ttvideoengine.log.a();
    }

    public final void c() {
        this.d = true;
        this.e.clear();
        this.mTTVideoErrorList.clear();
        this.g.clear();
        this.k.clear();
    }

    public final void d() {
        if (this.c.lt > 0) {
            this.e();
        } else {
            this.c.lt = System.currentTimeMillis();
            this.e();
        }
    }

    public final void e() {
        HashMap v3;
        long v8 = 0;
        HashMap v1 = null;
        if (this.c != null && (this.c.pt != v8 || this.c.st != v8)) {
            if (this.a != null) {
                TTVideoEngine ttVideoEngine = this.a.mTTVideoEngineRef.get();
                if (ttVideoEngine == null) {
                    v3 = v1;
                } else {
                    v3 = new HashMap();
                    if (ttVideoEngine.H != 0 && ttVideoEngine.H != 1) {
                        ((Map) v3).put("sv", "5.3");
                        ((Map) v3).put("pv", "1.0");
                        ((Map) v3).put("pc", "0");
                        ((Map) v3).put("sdk_version", "1.5.2");
                    } else {
                        ((Map) v3).put("sv", "5.3");
                        ((Map) v3).put("pv", "3.0");
                        ((Map) v3).put("pc", com.ss.ttm.player.m.a(14, ""));
                        ((Map) v3).put("sdk_version", "1.5.2");
                    }
                }
                if (v3 != null) {
                    this.c.sv = (String) ((Map) v3).get("sv");
                    this.c.pv = (String) ((Map) v3).get("pv");
                    this.c.pc = (String) ((Map) v3).get("pc");
                    this.c.sdk_version = (String) ((Map) v3).get("sdk_version");
                }

                ttVideoEngine = this.a.mTTVideoEngineRef.get();
                if (ttVideoEngine != null) {
                    IMediaPlayerClient mediaPlayerClient = ttVideoEngine.mMediaPlayerClient;
                    if (mediaPlayerClient != null) {
                        HashMap v0_1 = new HashMap();
                        ((Map) v0_1).put("vps", Long.valueOf(mediaPlayerClient.getLongOption(45)));
                        ((Map) v0_1).put("vds", Long.valueOf(mediaPlayerClient.getLongOption(46)));
                        v1 = v0_1;
                    }
                }

                if (v1 == null) {
                } else {
                    this.c.vps = ((Long) ((Map) v1).get("vps")).longValue();
                    this.c.vds = ((Long) ((Map) v1).get("vds")).longValue();
                }
            }
            this.c.v = this.b;
            this.c.n = this.h;
            this.c.lf = this.preResolutionString;
            this.c.df = this.currentResolutionString;
            this.c.merror = this.k;
            v3 = new HashMap();
            for (int v1_1 = 0; v1_1 < this.e.size(); ++v1_1) {
                v3.put(String.format("fetch%d", Integer.valueOf(v1_1)), ((TTVideoError) this.e.get(v1_1)).toMap());
            }

            for (int v1_1 = 0; v1_1 < this.mTTVideoErrorList.size(); ++v1_1) {
                v3.put(String.format("ldns%d", Integer.valueOf(v1_1)), ((TTVideoError) this.mTTVideoErrorList.get(v1_1)).toMap());
            }

            for (int v0_2 = 0; v0_2 < this.g.size(); ++v0_2) {
                v3.put(String.format("error%d", Integer.valueOf(v0_2)), this.g.get(v0_2));
            }

            v3.put("log", this.l);
            this.c.ex = ((Map) v3);
            if (this.c.br > 0) {
                this.c.br = 1;
            }

            if (this.m != null) {
                this.c.videoDuration = ((Integer) this.m.get("duration")).intValue();
                this.c.videoSize = ((Integer) ((Map) this.m.get("size")).get(this.currentResolutionString)).intValue();
            }

            VideoEventManager videoEventManager = VideoEventManager.instance;
            com.ss.ttvideoengine.log.a v1_2 = this.c;
            HashMap hashMap = new HashMap();
            hashMap.put("log_type", "video_playq");
            hashMap.put("vsc", Integer.valueOf(v1_2.vsc));
            hashMap.put("sdk_version", v1_2.sdk_version);
            hashMap.put("sv", v1_2.sv);
            hashMap.put("pv", v1_2.pv);
            hashMap.put("pc", v1_2.pc);
            hashMap.put("v", v1_2.v);
            hashMap.put("pt", Long.valueOf(v1_2.pt));
            hashMap.put("at", Long.valueOf(v1_2.at));
            hashMap.put("vt", Long.valueOf(v1_2.vt));
            hashMap.put("et", Long.valueOf(v1_2.errorTime));
            hashMap.put("lt", Long.valueOf(v1_2.lt));
            hashMap.put("st", Long.valueOf(v1_2.st));
            hashMap.put("bft", Long.valueOf(v8));
            hashMap.put("bc", Integer.valueOf(v1_2.bc));
            hashMap.put("br", Integer.valueOf(v1_2.br));
            hashMap.put("vu", v1_2.n);
            hashMap.put("vd", Integer.valueOf(v1_2.videoDuration));
            hashMap.put("vs", Integer.valueOf(v1_2.videoSize));
            hashMap.put("vps", Long.valueOf(v1_2.vps));
            hashMap.put("vds", Long.valueOf(v1_2.vds));
            hashMap.put("video_preload_size", Integer.valueOf(0));
            hashMap.put("errt", Integer.valueOf(v1_2.errt));
            hashMap.put("errc", Integer.valueOf(v1_2.errorCode));
            hashMap.put("df", v1_2.df);
            hashMap.put("lf", v1_2.lf);
            hashMap.put("merror", v1_2.merror);
            hashMap.put("hijack", Integer.valueOf(v1_2.hijack));
            hashMap.put("ex", v1_2.ex);
            hashMap.put("initial_url", v1_2.initial_url);
            videoEventManager.addEvent(new JSONObject(hashMap));
        }
    }
}

